package com.kongxx.wicketstudy.tutorial.user.web;

import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.panel.FeedbackPanel;
import org.apache.wicket.model.CompoundPropertyModel;

import com.kongxx.wicketstudy.tutorial.user.model.User;
import com.kongxx.wicketstudy.tutorial.user.service.UserService;
import com.kongxx.wicketstudy.tutorial.user.service.impl.UserServiceImpl;

public class UserAdd extends WebPage {
	private User user = new User("", "", "", "");
	
	public UserAdd() {
		add(new FeedbackPanel("feedback"));
		Form form = new Form("myform", new CompoundPropertyModel(user)) {
			protected void onSubmit() {
				UserService userService = new UserServiceImpl();
				userService.add(user);
				setResponsePage(UserList.class);
			}
		};
		
		TextField id = new TextField("id");
		id.setRequired(true);
		form.add(id);

		TextField username = new TextField("username");
		username.setRequired(true);
		form.add(username);
		
		TextField password = new TextField("password");
		password.setRequired(true);
		form.add(password);
		
		TextField description = new TextField("description");
		description.setRequired(true);
		form.add(description);

		add(form);
	}
}
